package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.StringUtils;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.UserMsgSendTotalDao;
import com.kly.user.db.entity.UserMsgSendTotalEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

/**
* User: linqu
* Date: 2023-09-25
* Time: 10:01:01.912
*/

@Repository
public class UserMsgSendTotalDaoImpl extends AbstractBaseMapper<UserMsgSendTotalEntity> implements UserMsgSendTotalDao {

    @Override
    public List<UserMsgSendTotalEntity> queryByUserCode(String fromUserCode, String toUserCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        if (StringUtils.isNotEmpty(fromUserCode)) {
            params.put("fromUserCode", fromUserCode);
        }
        if (StringUtils.isNotEmpty(toUserCode)) {
            params.put("toUserCode", toUserCode);
        }
        return this.selectByParams(params);
    }

    @Override
    public UserMsgSendTotalEntity getUserMsgSendTotal(String fromUserCode, String toUserCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        if (StringUtils.isNotEmpty(fromUserCode)) {
            params.put("fromUserCode", fromUserCode);
        }
        if (StringUtils.isNotEmpty(toUserCode)) {
            params.put("toUserCode", toUserCode);
        }
        return this.getSqlSession().selectOne(this.getStatement("getUserMsgSendTotal"), params);
    }

    @Override
    public UserMsgSendTotalEntity getUserSendMsgNum(String chatterUserCode, String fromUserCode, String toUserCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        params.put("fromUserCode", fromUserCode);
        params.put("toUserCode", toUserCode);
        return  this.getSqlSession().selectOne(this.getStatement("getUserSendMsgNum"), params);
    }

    @Override
    public int getUserSendMsgCount(String fromUserCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("fromUserCode", fromUserCode);
        return this.getSqlSession().selectOne(this.getStatement("getUserSendMsgCount"), params);
    }

    @Override
    public List<UserMsgSendTotalEntity> listOnlineUserChats(String chatterUserCode, String modelUserCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        params.put("modelUserCode", modelUserCode);
        return this.getSqlSession().selectList(this.getStatement("listOnlineUserChats"), params);
    }
}